home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / DCLAP 4j / DApp / RTFViewer.cpp < prev    next >
Encoding:
Text File  |  1995-12-17  |  3.0 KB  |  144 lines  |  [TEXT/R*ch]

  1. // RTFViewer.cpp
  2. // d.g.gilbert --Rich Text Format (RTF) document display, using DClAp library
  3. // may 1994
  4.  
  5.  
  6. #include "DClap.h"
  7. #include "DRTFView.h"
  8.  
  9. #if 0
  10. #include "rtf.h"
  11. #include "drtfwriter.h"
  12. #include "drtfdoc.h"
  13. #endif
  14.  
  15.  
  16. class DRTFViewApp : public DApplication
  17. {
  18. public:
  19.     enum myapptasks { kRTFdemo=1301 };
  20.     DRTFsetup* fRTFsetup;    
  21.  
  22.     void IMyApp(void);     
  23.     virtual ~DRTFViewApp();
  24.     
  25.     virtual void RTFdemo(void);    
  26.  
  27.     virtual void OpenDocument(DFile* aFile);    // override
  28.     virtual void OpenHelp(DFile* aFile); // override
  29.     virtual void SetUpMenus(void);    // override
  30.     virtual    Boolean IsMyAction(DTaskMaster* action); //override
  31. };
  32.  
  33.  
  34.  
  35.  
  36. extern "C" short Main(void)
  37. {
  38.   DRTFViewApp* myapp = new DRTFViewApp();
  39.   myapp->IMyApp();
  40.   myapp->Run();
  41.   delete myapp; 
  42.   return 0;
  43. }
  44.  
  45.  
  46. void DRTFViewApp::IMyApp(void)
  47. {
  48.     IApplication();
  49.     fRTFsetup= new DRTFsetup(); // depends on gFileManager created in IApplication
  50. }     
  51.  
  52. DRTFViewApp::~DRTFViewApp()
  53. {
  54.     delete fRTFsetup;
  55. }
  56.  
  57. void DRTFViewApp::SetUpMenus(void)
  58. {
  59.     DApplication::SetUpMenus();
  60. #if 0
  61.     DMenu* sMenu = NewMenu(kRTFdemo, "RTF");
  62.     sMenu->AddItem( DRTFViewApp::kRTFdemo, "Open RTF file...");
  63. #endif
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70. void DRTFViewApp::RTFdemo()
  71. {
  72.     char* filename= (char*) gFileManager->GetInputFileName(NULL,NULL);
  73.     if (filename) {
  74.         filename= StrDup(filename);
  75.         char* shortname= (char*)gFileManager->FilenameFromPath(filename);
  76.         gCursor->watch();
  77.         DWindow* win= new DWindow( 0, this, DWindow::document, -1, -1, -10, -10, shortname);
  78.  
  79.         short docwidth= gPrintManager->PageWidth();    
  80.         DRTFView* rtfdoc= new DRTFView( 0, win, docwidth, 0);
  81.         rtfdoc->SetResize( DView::matchsuper, DView::relsuper);
  82.         //rtfdoc->SetSlateBorder( false);
  83.         rtfdoc->ShowFile( filename);    
  84.             
  85.         win->Open();
  86.         rtfdoc->SizeToSuperview( win, true, false); // this needs to adjust for if view has scrollbar !
  87.         MemFree(filename);
  88.         gCursor->arrow();
  89.         }
  90. }
  91.  
  92.  
  93. void DRTFViewApp::OpenHelp(DFile* aFile)
  94. {
  95.     if (!aFile->Exists()) {
  96.         Message(MSG_OK,"Can't find help file '%s'",aFile->GetName());
  97.         return;
  98.         }
  99. #if 1
  100.     this->OpenDocument(aFile); 
  101. #else
  102.     DApplication::OpenHelp(aFile);
  103. #endif 
  104. }
  105.  
  106. void    DRTFViewApp::OpenDocument(DFile* aFile)
  107. {
  108.     // default OpenDoc is to use Vibrant's text display
  109.     if (aFile && aFile->Exists()) {
  110.  
  111.         gCursor->watch();
  112.         aFile->CloseFile(); // ShowFile manages this..
  113.         char* shortname= (char*)aFile->GetShortname();
  114.         const char* fullname= aFile->GetName();
  115.         DWindow* win= new DWindow(0, this, DWindow::document, -1, -1, -10, -10, shortname);
  116.  
  117.         short docwidth= gPrintManager->PageWidth();    
  118.         DRTFView* rtfdoc= new DRTFView( 0, win, docwidth, 0);
  119.         rtfdoc->SetResize( DView::matchsuper, DView::relsuper);
  120.         //rtfdoc->SetSlateBorder( false);
  121.         rtfdoc->ShowFile( (char*)fullname);
  122.  
  123.         win->Open();
  124.         rtfdoc->SizeToSuperview( win, true, false); // this needs to adjust for if view has scrollbar !
  125.         gCursor->arrow();
  126.         }
  127. }
  128.  
  129.  
  130. Boolean DRTFViewApp::IsMyAction(DTaskMaster* action) 
  131. {
  132.     DWindow* win;
  133.     
  134.     switch(action->Id()) {
  135.  
  136.         case kRTFdemo: this->RTFdemo(); return true;
  137.         
  138.         default: 
  139.             return DApplication::IsMyAction(action);
  140.         }
  141. }
  142.  
  143.  
  144.